﻿using SD.TeachSystem.Service;

namespace SD.TeachSystem.API.Service
{
    public static class StartExtensions 
    {
        /// <summary>
        /// 配置注入服务
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddStartService(this IServiceCollection services)
        {
            #region ModelContext默认为Scoped生命周期注入方式需保持一致

            //services.AddSingleton<DemoService>();

            //// 使用懒加载初始化注册AllLazyService服务
            //services.AddSingleton<AllLazyService>(s =>
            //    new AllLazyService(
            //        new Lazy<DemoService>(s.GetRequiredService<DemoService>)
            //    )
            //);

            #endregion

            services.AddScoped<DemoService>();

            // 使用懒加载初始化注册AllLazyService服务
            services.AddScoped<AllLazyService>(s =>
                new AllLazyService(
                    new Lazy<DemoService>(s.GetRequiredService<DemoService>)
                )
            );

            return services;
        }
    }
}
